<?php defined('SYSPATH') or die('No direct script access.');
 
class parse {

    /**
     * Parses date in local foramt and returns date in ISO format (YYYY-MM-DD).
     */
    public static function date($dateInLocalFormat) {
        if (! valid::isDate($dateInLocalFormat)) {
            return null;
        }
        // $dateParts = preg_split(Kohana::lang('dateTimeFormat.separator'), $dateInLocalFormat);
        preg_match(Kohana::lang('dateTimeFormat.pattern'), $dateInLocalFormat, $dateParts);
        $ymdOrder = Kohana::lang('dateTimeFormat.order');
        $year = $dateParts[$ymdOrder['y']];
        $month = substr('0' . $dateParts[$ymdOrder['m']], -2);
        $day = substr('0' . $dateParts[$ymdOrder['d']], -2);
        return  $year . '-' . $month . '-' . $day;
    }
}
 
?>
